/**
 * Created by huotaol on 2017/5/4.
 */
import store from "../redux/store/configStore";
import * as BuyCarAction from "../redux/action/BuyCar";
import * as HomepageAction from "../redux/action/homePage";
import {request} from "../../common/util/RequestUtil";
import * as Util from "../../common/util/Util";
import {Alert, Platform} from "react-native";
import * as CustomStyle from "../../common/style/CustomStyle";


export const VERSION_CODE = 2;

/*界面布局完成后请求数据*/
export default function start() {
    _loadVersion();
    _loadDataList();
    _loadBrand();
}

function _loadVersion() {
    const url = 'http://m.chehangjia.cn/download/get_new_version.json';
    console.log('_loadVersion ');
    request(url)
        .then(json => {
            console.log('_loadVersion ' + json);
            const {version, url} = json;
            if (parseInt(version) > VERSION_CODE) {
                console.log('_loadVersion url ' + url);
                if (CustomStyle.OS_ANDROID === Platform.OS) {
                    Alert.alert('版本升级', '有新版本，是否升级', [
                        {text: '确定', onPress: () => Util.openURL(url)},
                    ]);
                }
            }
        }).catch(err => {
        console.log('_loadVersion err ' + err);
    });
}

function _loadBrand() {
    store.dispatch(BuyCarAction.requestBrand());
}


function _loadDataList() {
    store.dispatch(HomepageAction.requestAreaList());
}





